.TH "OSM2PGSQL-REPLICATION" "1" "1.6.0" "" ""
.SH NAME
osm2pgsql-replication \- osm2pgsql database updater
.SH SYNOPSIS
.B osm2pgsql-replication
[-h] {init,update,status} ...
.SH DESCRIPTION
Update an osm2pgsql database with changes from a OSM replication server.
.br

.br
This tool initialises the updating process by looking at the import file
.br
or the newest object in the database. The state is then saved in a table
.br
in the database. Subsequent runs download newly available data and apply
.br
it to the database.
.br

.br
See the help of the \(cqinit\(cq and \(cqupdate\(cq command for more information on
.br
how to use osm2pgsql\-replication.
.SH OPTIONS


.SS
\fBSub-commands\fR
.TP
\fBosm2pgsql-replication\fR \fI\,init\/\fR
    Initialise the replication process.
.TP
\fBosm2pgsql-replication\fR \fI\,update\/\fR
    Download newly available data and apply it to the database.
.TP
\fBosm2pgsql-replication\fR \fI\,status\/\fR
    Print information about the current replication status, optionally as JSON.
.SH OPTIONS 'osm2pgsql-replication init'
usage: osm2pgsql-replication init [-h] [-q] [-v] [-d DB] [-U NAME] [-H HOST]
                                  [-P PORT] [-p PREFIX]
                                  [--osm-file FILE | --server URL]

Initialise the replication process.
.br

.br
There are two ways to initialise the replication process: if you have imported
.br
from a file that contains replication source information, then the
.br
initialisation process can use this and set up replication from there.
.br
Use the command \(cq%(prog)s \-\-osm\-file <filename>\(cq for this.
.br

.br
If the file has no replication information or you don't have the initial
.br
import file anymore then replication can be set up according to
.br
the data found in the database. It checks the planet_osm_way table for the
.br
newest way in the database and then queries the OSM API when the way was
.br
created. The date is used as the start date for replication. In this mode
.br
the minutely diffs from the OSM servers are used as a source. You can change
.br
this with the \(cq\-\-server\(cq parameter.



.TP
\fB\-q\fR, \fB\-\-quiet\fR
Print only error messages

.TP
\fB\-v\fR, \fB\-\-verbose\fR
Increase verboseness of output

.TP
\fB\-d\fR DB, \fB\-\-database\fR DB
Name of PostgreSQL database to connect to or conninfo string

.TP
\fB\-U\fR NAME, \fB\-\-username\fR NAME
PostgreSQL user name

.TP
\fB\-H\fR HOST, \fB\-\-host\fR HOST
Database server host name or socket location

.TP
\fB\-P\fR PORT, \fB\-\-port\fR PORT
Database server port

.TP
\fB\-p\fR PREFIX, \fB\-\-prefix\fR PREFIX
Prefix for table names (default 'planet_osm')

.TP
\fB\-\-osm\-file\fR FILE
Get replication information from the given file.

.TP
\fB\-\-server\fR URL
Use replication server at the given URL (default: https://planet.openstreetmap.org/replication/minute)

.SH OPTIONS 'osm2pgsql-replication update'
usage: osm2pgsql-replication update update [options] [-- param [param ...]]

Download newly available data and apply it to the database.
.br

.br
The data is downloaded in chunks of \(cq\-\-max\-diff\-size\(cq MB. Each chunk is
.br
saved in a temporary file and imported with osm2pgsql from there. The
.br
temporary file is normally deleted afterwards unless you state an explicit
.br
location with \(cq\-\-diff\-file\(cq. Once the database is up to date with the
.br
replication source, the update process exits with 0.
.br

.br
Any additional arguments to osm2pgsql need to be given after \(cq\-\-\(cq. Database
.br
and the prefix parameter are handed through to osm2pgsql. They do not need
.br
to be repeated. \(cq\-\-append\(cq and \(cq\-\-slim\(cq will always be added as well.
.br

.br
Use the \(cq\-\-post\-processing\(cq parameter to execute a script after osm2pgsql has
.br
run successfully. If the updates consists of multiple runs because the
.br
maximum size of downloaded data was reached, then the script is executed
.br
each time that osm2pgsql has run. When the post\-processing fails, then
.br
the entire update run is considered a failure and the replication information
.br
is not updated. That means that when 'update' is run the next time it will
.br
recommence with downloading the diffs again and reapplying them to the
.br
database. This is usually safe. The script receives two parameters:
.br
the sequence ID and timestamp of the last successful run. The timestamp
.br
may be missing in the rare case that the replication service stops responding
.br
after the updates have been downloaded.

.TP
\fBparam\fR
Extra parameters to hand in to osm2pgsql.

.TP
\fB\-\-diff\-file\fR FILE
File to save changes before they are applied to osm2pgsql.

.TP
\fB\-\-max\-diff\-size\fR \fI\,MAX_DIFF_SIZE\/\fR
Maximum data to load in MB (default: 500MB)

.TP
\fB\-\-osm2pgsql\-cmd\fR \fI\,OSM2PGSQL_CMD\/\fR
Path to osm2pgsql command (default: osm2pgsql)

.TP
\fB\-\-once\fR
Run updates only once, even when more data is available.

.TP
\fB\-\-post\-processing\fR SCRIPT
Post\-processing script to run after each execution of osm2pgsql.

.TP
\fB\-q\fR, \fB\-\-quiet\fR
Print only error messages

.TP
\fB\-v\fR, \fB\-\-verbose\fR
Increase verboseness of output

.TP
\fB\-d\fR DB, \fB\-\-database\fR DB
Name of PostgreSQL database to connect to or conninfo string

.TP
\fB\-U\fR NAME, \fB\-\-username\fR NAME
PostgreSQL user name

.TP
\fB\-H\fR HOST, \fB\-\-host\fR HOST
Database server host name or socket location

.TP
\fB\-P\fR PORT, \fB\-\-port\fR PORT
Database server port

.TP
\fB\-p\fR PREFIX, \fB\-\-prefix\fR PREFIX
Prefix for table names (default 'planet_osm')


.SH OPTIONS 'osm2pgsql-replication status'
usage: osm2pgsql-replication status [-h] [-q] [-v] [-d DB] [-U NAME] [-H HOST]
                                    [-P PORT] [-p PREFIX] [--json]

Print information about the current replication status, optionally as JSON.
.br

.br
Sample output:
.br

.br
    2021\-08\-17 15:20:28 [INFO]: Using replication service 'https://planet.openstreetmap.org/replication/minute', which is at sequence 4675115 ( 2021\-08\-17T13:19:43Z )
.br
    2021\-08\-17 15:20:28 [INFO]: Replication server's most recent data is <1 minute old
.br
    2021\-08\-17 15:20:28 [INFO]: Local database is 8288 sequences behind the server, i.e. 5 day(s) 20 hour(s) 58 minute(s)
.br
    2021\-08\-17 15:20:28 [INFO]: Local database's most recent data is 5 day(s) 20 hour(s) 59 minute(s) old
.br

.br

.br
With the \(cq\-\-json\(cq option, the status is printed as a json object.
.br

.br
    {
.br
      "server": {
.br
        "base_url": "https://planet.openstreetmap.org/replication/minute",
.br
        "sequence": 4675116,
.br
        "timestamp": "2021\-08\-17T13:20:43Z",
.br
        "age_sec": 27
.br
      },
.br
      "local": {
.br
        "sequence": 4666827,
.br
        "timestamp": "2021\-08\-11T16:21:09Z",
.br
        "age_sec": 507601
.br
      },
.br
      "status": 0
.br
    }
.br

.br

.br
\(cqstatus\(cq is 0 if there were no problems getting the status. 1 & 2 for
.br
improperly set up replication. 3 for network issues. If status ≠ 0, then
.br
the \(cqerror\(cq key is an error message (as string). \(cqstatus\(cq is used as the
.br
exit code.
.br

.br
\(cqserver\(cq is the replication server's current status. \(cqsequence\(cq is it's
.br
sequence number, \(cqtimestamp\(cq the time of that, and 'age_sec' the age of the
.br
data in seconds.
.br

.br
\(cqlocal\(cq is the status of your server.


.TP
\fB\-\-json\fR
Output status as json.

.TP
\fB\-q\fR, \fB\-\-quiet\fR
Print only error messages

.TP
\fB\-v\fR, \fB\-\-verbose\fR
Increase verboseness of output

.TP
\fB\-d\fR DB, \fB\-\-database\fR DB
Name of PostgreSQL database to connect to or conninfo string

.TP
\fB\-U\fR NAME, \fB\-\-username\fR NAME
PostgreSQL user name

.TP
\fB\-H\fR HOST, \fB\-\-host\fR HOST
Database server host name or socket location

.TP
\fB\-P\fR PORT, \fB\-\-port\fR PORT
Database server port

.TP
\fB\-p\fR PREFIX, \fB\-\-prefix\fR PREFIX
Prefix for table names (default 'planet_osm')

.SH SEE ALSO
* osm2pgsql website (https://osm2pgsql.org)
.br
* osm2pgsql manual (https://osm2pgsql.org/doc/manual.html)

